<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%--
  Created by IntelliJ IDEA.
  User: zzz
  Date: 2020/2/9
  Time: 9:37
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="utf-8" />
    <title>order</title>
    <link rel="stylesheet" type="text/css" href="${APP_PATH}/portal/css/public.css"/>
    <link rel="stylesheet" type="text/css" href="${APP_PATH}/portal/css/proList.css" />
    <link rel="stylesheet" type="text/css" href="${APP_PATH}/portal/css/mygxin.css" />
</head>
<body>
<!----------------------------------------order------------------>
<jsp:include page="/WEB-INF/jsps/Portal/common/top.jsp"/>
<div class="order cart mt">
    <!-----------------site------------------->
    <div class="site">
        <p class="wrapper clearfix">
            <span class="fl">订单确认</span>
            <img class="top" src="${APP_PATH}/portal/img/temp/cartTop02.png">
        </p>
    </div>
    <!-----------------orderCon------------------->
    <div class="orderCon wrapper clearfix">
        <div class="orderL fl">
            <!--------h3---------------->
            <h3>收件信息<a href="javascript:;" class="insert fr">新增地址</a></h3>
            <!--------addres---------------->
            <div class="addres clearfix">
                <c:forEach items="${accountInfo.addressInfoList}" var="addressInfo" varStatus="i">
                    <div id="${addressInfo.address.adid}" class="addre fl ${addressInfo.address.ispretermission == 1?"on":""}">
                        <div class="tit clearfix">
                            <p class="fl">${addressInfo.address.consignee}
                                <span class="default">${addressInfo.address.ispretermission == 1?"[默认地址]":""}</span>
                            </p>
                            <p class="fr">
                                <c:if test="${addressInfo.address.ispretermission == 0}">
                                    <a href="${APP_PATH}/user/setAddDefault?adid=${addressInfo.address.adid}" class="setDefault">设为默认</a>
                                    <span>|</span>
                                </c:if>
                                <a href="${APP_PATH}/user/deleteAddress2?adid=${addressInfo.address.adid}">删除</a>
                                <span>|</span>
                                <a href="javascript:;" id="${addressInfo.address.adid}" class="edit">编辑</a>
                            </p>
                        </div>
                        <div class="addCon">
                            <p>${addressInfo.province.pname}&nbsp;${addressInfo.city.cname}&nbsp;${addressInfo.district.dname}&nbsp;${addressInfo.area.arname}</p>
                            <p>${addressInfo.address.cphone}</p>
                        </div>
                    </div>
                </c:forEach>


            </div>
            <h3>支付方式</h3>
            <!--------way---------------->
            <div class="way clearfix">
                <img id="pay1" class="on" src="${APP_PATH}/portal/img/temp/way01.jpg">
                <img id="pay2" src="${APP_PATH}/portal/img/temp/way02.jpg">
                <img id="pay3" src="${APP_PATH}/portal/img/temp/way03.jpg">
                <img id="pay4" src="${APP_PATH}/portal/img/temp/way04.jpg">
            </div>
            <h3>选择快递</h3>
            <!--------dis---------------->
            <div class="dis clearfix">
                <span id="e1" class="on">顺风快递</span>
                <span id="e2">百世汇通</span>
                <span id="e3">圆通快递</span>
                <span id="e4">中通快递</span>
            </div>
        </div>
        <div class="orderR fr">
            <div class="msg">
                <h3>订单内容<a href="${APP_PATH}/toTrolley" class="fr">返回购物车</a></h3>
                <!--------ul---------------->
                <c:forEach items="${requestScope.accountInfo.trolleyInfoList}" var="trolleyInfo">
                    <input type="hidden" class="poid" value="${trolleyInfo.pre_order.poid}"/>
                    <ul class="clearfix">
                        <li class="fl">
                            <img style="width: 75px;" src="${APP_PATH}/${trolleyInfo.furnitureKinds.fkface}">
                        </li>
                        <li class="fl">
                            <p>${trolleyInfo.furniture.fname}</p>
                            <p>颜色分类：${trolleyInfo.furnitureKinds.fkname}</p>
                            <p>数量：${trolleyInfo.pre_order.count}</p>
                        </li>
                        <li class="fr">￥<span class="price"><fmt:formatNumber type="number" value="${trolleyInfo.furnitureKinds.fkprice * trolleyInfo.pre_order.count}" pattern="#.00" /></span></li>
                    </ul>
                </c:forEach>

            </div>
            <!--------tips---------------->
            <div class="tips">
                <p><span class="fl">商品金额：</span><span class="fr">￥<span class="allPrice"></span></span></p>
                <p><span class="fl">优惠金额：</span><span class="fr">￥0.00</span></p>
                <p><span class="fl">运费：</span><span class="fr">免运费</span></p>
            </div>
            <!--------tips count---------------->
            <div class="count tips">
                <p><span class="fl">合计：</span><span class="fr">￥<span class="allPrice"></span></span></p>
            </div>
            <!--<input type="button" name="" value="去支付"> -->
            <a href="javascript:;" class="pay" onclick="pay()">去支付</a>
        </div>
    </div>
</div>
<!--编辑弹框-->
<!--遮罩-->
<div class="mask"></div>
<div class="adddz">
    <form id="add" action="" method="post">
        <input type="hidden" id="adid" name="adid"/>
        <input type="text" id="consignee" name="consignee" placeholder="姓名" class="on" />
        <input type="text" id="cphone" name="cphone" placeholder="手机号" />
        <div class="city">
            <select id="province">
                <option value="省份/自治区">省份/自治区</option>
            </select>
            <select id="city">
                <option value="城市/地区">城市/地区</option>
            </select>
            <select id="district">
                <option value="区/县">区/县</option>
            </select>
            <select id="area" name="ar_arid">
                <option value="配送区域">配送区域</option>
            </select>
        </div>
        <textarea id="address" name="address" rows="" cols="" placeholder="详细地址"></textarea>
        <input id="postcode" name="postcode" type="text" placeholder="邮政编码" />
        <div class="bc">
            <input type="submit" value="保存" />
            <input type="button" value="取消" />
        </div>
    </form>
</div>

<!--返回顶部-->
<jsp:include page="/WEB-INF/jsps/Portal/common/gotop.jsp"/>
<!--footer-->
<jsp:include page="/WEB-INF/jsps/Portal/common/bottom.jsp"/>
<script src="${APP_PATH}/portal/js/jquery-1.12.4.min.js" type="text/javascript" charset="utf-8"></script>
<script src="${APP_PATH}/portal/js/public.js" type="text/javascript" charset="utf-8"></script>
<script src="${APP_PATH}/portal/js/pro.js" type="text/javascript" charset="utf-8"></script>
<script src="${APP_PATH}/portal/js/user.js" type="text/javascript" charset="utf-8"></script>
</body>
</html>
<script>
    $(function () {
        if(${requestScope.msg != null}){
            alert('${requestScope.msg}');
        }
        var count = 0;
        $(".price").each(function () {
            count += parseInt($(this).html());
        });
        $(".allPrice").html(count.toFixed(2));


        $.ajax({
            url : "${APP_PATH}/user/getAllProvince",
            method : "GET",
            success : function (result) {
                if(result.success){
                    var provinceList = result.data;
                    var provinceContent = "";
                    provinceContent +='<option value="0">省份/自治区</option>';
                    for(var i = 0; i < provinceList.length; i++){
                        provinceContent +='<option value="'+provinceList[i].pid+'">'+provinceList[i].pname+'</option>';
                    }
                    $("#province").html(provinceContent);
                }
            }
        });

        $("#province").change(function () {
            getCity($(this).val(),0);
            $("#district").html('<option value="0">区/县</option>');
            $("#area").html('<option value="0">配送区域</option>');
        });
        $("#city").change(function () {
            getDistrict($(this).val(),0);
            $("#area").html('<option value="0">配送区域</option>');
        });
        $("#district").change(function () {
            getArea($(this).val(),0);
        });
    });

    function pay() {
        var poids = new Array();
        $(".poid").each(function () {
            poids.push($(this).val());
        });
        var adid = $(".addres").find(".on").attr("id");
        var price = $(".allPrice").html();
        var payWay = $(".way").find(".on").attr("id");
        if(payWay == "pay4"){
            payWay = 0;
        }else{
            payWay = 1;
        }
        var eWay = $(".dis").find(".on").attr("id");
      $.ajax({
            url : "${APP_PATH}/order/insertOrder",
            method : "POST",
            data :{
                poids : poids,
                ad_adid : adid,
                paytype : payWay,
                eWay : eWay,
                oprice : price
            },
          success : function (result) {
              if(result.success){
                    window.location.href="${APP_PATH}/toCompleteAccount";
              }else {
                  alert("订单库存不足！");
                  window.location.href="${APP_PATH}/toTrolley";
              }
          }
        });
    }

    function getAddInfo(id) {
       if(id != undefined){
           $("#add").attr("action","${APP_PATH}/user/updateAddress2");
           $("#adid").val(id);
           $.ajax({
               url: "${APP_PATH}/user/getAddress",
               method: "GET",
               data: {
                   adid: id
               },
               success: function (result) {
                   if (result.success) {
                       var address = result.data.address;
                       var area = result.data.area;
                       var district = result.data.district;
                       var city = result.data.city;
                       var province = result.data.province;
                       $("#adid").val(address.adid);
                       $("#consignee").val(address.consignee);
                       $("#cphone").val(address.cphone);
                       $("#address").val(address.address);
                       $("#postcode").val(address.postcode);
                       $("#province").val(province.pid);
                       getArea(district.did,area.arid);
                       getDistrict(city.cid,district.did);
                       getCity(province.pid,city.cid);
                   }
               }
           });
       }else{
           $("#add").attr("action","${APP_PATH}/user/insertAddress2");
       }
    }

    function getCity(pid,cid) {
        $.ajax({
            url : "${APP_PATH}/user/getCityByPid",
            method : "GET",
            data : {
                pid : pid
            },
            success : function (result) {
                if(result.success){
                    var cityList = result.data;
                    var cityContent = "";
                    cityContent +='<option value="0">城市/地区</option>';
                    for(var i = 0; i < cityList.length; i++){
                        cityContent +='<option value="'+ cityList[i].cid+'">'+ cityList[i].cname+'</option>';
                    }
                        $("#city").html(cityContent);
                        $("#city").val(cid);
                }
            }
        });
    }

    function getDistrict(cid,did) {
        $.ajax({
            url : "${APP_PATH}/user/getDistrictByCid",
            method : "GET",
            data : {
                cid : cid
            },
            success : function (result) {
                if(result.success){
                    var districtList = result.data;
                    var districtContent = "";
                    districtContent +='<option value="0">区/县</option>';
                    for(var i = 0; i < districtList.length; i++){
                        districtContent +='<option value="'+ districtList[i].did+'">'+ districtList[i].dname+'</option>';
                    }
                        $("#district").html( districtContent);
                        $("#district").val(did);
                }
            }
        });
    }

    function getArea(did,arid) {
        $.ajax({
            url : "${APP_PATH}/user/getAreaByDid",
            method : "GET",
            data : {
                did : did
            },
            success : function (result) {
                if(result.success){
                    var areaList = result.data;
                    var areaContent = "";
                    areaContent +='<option value="0">配送区域</option>';
                    for(var i = 0; i < areaList.length; i++){
                        areaContent +='<option value="'+ areaList[i].arid+'">'+ areaList[i].arname+'</option>';
                    }
                        $("#area").html( areaContent);
                        $("#area").val(arid);
                }
            }
        });
    }
</script>